<?php

namespace Biz\service\GoodsTestActivity;

use Biz\model\bigData\UserConsumeDecisionScore;
use Biz\service\NewProduct\NewProductWinnerListService;

class BigDataService
{

    /**
     * @param array $uidArr
     * @return array
     */
    public static function getScoreMap(array $uidArr): array
    {
        if ($uidArr) {
            $where['uid'] = $uidArr;
            $where['day'] = date('Ymd', strtotime('-1 day'));
            $data = UserConsumeDecisionScore::select('*', $where);
            if (empty($data)) {
                $where['day'] = date('Ymd', strtotime('-2 day'));//容错处理
                $data = UserConsumeDecisionScore::select('*', $where);
            }
            $data = $data ? NewProductWinnerListService::handleData($data, 'uid') : [];
            $res = [];
            foreach ($uidArr as $uid) {
                $res[$uid] = [
                    ['tag' => UserConsumeDecisionScore::PRODUCT_SCORE, 'score' => $data[$uid]['product_score'] ?? 0],
                    ['tag' => UserConsumeDecisionScore::WIKI_SCORE, 'score' => $data[$uid]['wiki_score'] ?? 0],
                    ['tag' => UserConsumeDecisionScore::CREDIT_SCORE, 'score' => $data[$uid]['credit_score'] ?? 0],
                ];
            }
            return [$res, $data];
        } else {
            return [];
        }

    }
}